package Meins;

import java.awt.Color;

import javax.media.j3d.Appearance;
import javax.media.j3d.Background;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Material;
import javax.media.j3d.SpotLight;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JFrame;
import javax.media.j3d.*;
import javax.vecmath.*;

import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Cylinder;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.geometry.Cone;
import com.sun.j3d.utils.universe.SimpleUniverse;

import com.sun.j3d.utils.universe.SimpleUniverse;

public class Final extends JFrame {

	private BranchGroup rootBranchGroup;
	private TransformGroup rootTransformGroup;
	private Canvas3D canvas;
	private SimpleUniverse simpUniv;
	
	public Final(){
		super();
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		rootBranchGroup = new BranchGroup();
		rootTransformGroup = new TransformGroup();
		rootBranchGroup.addChild(rootTransformGroup);
		rootTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
		simpUniv = new SimpleUniverse(canvas);
		simpUniv.getViewingPlatform().setNominalViewingTransform();
		createSceneGraph(simpUniv);

		mausverhalten();

		setSize(1000, 700);
		getContentPane().add("Center", canvas);
		setVisible(true);
	
		
	}
	
	public void mausverhalten() {

		OrbitBehavior ob = new OrbitBehavior(canvas);
		ob.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
				Double.MAX_VALUE));
		simpUniv.getViewingPlatform().setViewPlatformBehavior(ob);
	}
	
	public void createSceneGraph(SimpleUniverse su) {
		
		//Koordinaten sys
		
		
			// Create X axis  
			LineArray axisXLines=new LineArray(2,LineArray.COORDINATES);
		    rootBranchGroup.addChild(new Shape3D(axisXLines));
		      
		    axisXLines.setCoordinate(0,new Point3f(-1.0f,0.0f,0.0f));
		    axisXLines.setCoordinate(1,new Point3f(1.0f,0.0f,0.0f));  
		    
		    // Create Y axis  
		    LineArray axisYLines=new LineArray(2,LineArray.COORDINATES);
		    rootBranchGroup.addChild(new Shape3D(axisYLines));
		      
		    axisYLines.setCoordinate(0,new Point3f(0.0f,-1.0f,0.0f));
		    axisYLines.setCoordinate(1,new Point3f(0.0f,1.0f,0.0f));
		      
		    // Create Z axis 
		    
		    LineArray axisYLines1=new LineArray(10,LineArray.COORDINATES);
		    rootBranchGroup.addChild(new Shape3D(axisYLines1));
		    axisYLines1.setCoordinate(0,new Point3f(0.0f,0.0f,-1.0f));
		    axisYLines1.setCoordinate(1,new Point3f(0.0f,0.0f,1.0f));
	
		    
		
		
		
		
		// Hintergrund
		Background bg = new Background(new Color3f(0.2f, 0.2f, 0.2f));
		BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
				Double.MAX_VALUE);
		bg.setApplicationBounds(bounds);
		rootBranchGroup.addChild(bg);
		rootBranchGroup.compile();
		su.addBranchGraph(rootBranchGroup);
		
	}
	
	public static void setToMyDefaultAppearance(Appearance app, Color3f col) {
		app.setMaterial(new Material(col, col, col, col, 150.0f));
	}
	
	
	public static void main(String[] args) {

		new Final();

	}

}
